package com.example.lancooznbk;

import android.app.Application;
import android.content.Context;
import android.os.StrictMode;
import android.support.multidex.MultiDex;
import android.util.Log;

import com.example.lancooznbk.model.result.LearnTypeEntity;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.RxRetrofitApp;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;
import com.squareup.leakcanary.LeakCanary;

import java.util.List;

/**
 * Created by tangminglong on 17/7/28.
 */

public class MyApplication extends Application{

    private List<LearnTypeEntity> learnTypeEntities;

    @Override
    public void onCreate() {
        super.onCreate();
        RxRetrofitApp.init(this,false);
        if (RxRetrofitApp.isDebug()){
          enabledStrictMode();
        }
        //LeakCanary.install(this);//内存泄漏检查工具
        ToastUtils.init(this);
        FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(true)
                .tag("ZNBK")
                .build();
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
        Logger.addLogAdapter(new AndroidLogAdapter(){
            @Override
            public boolean isLoggable(int priority, String tag) {
                return RxRetrofitApp.isDebug();
            }
        });
    }


    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    /**
     * 调试的时候开启严苛模式进行代码检查，正式发布的时候不能够调用
     */
    private static void enabledStrictMode(){
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()   // or .detectAll() for all detectable problems
                .penaltyLog()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects()
                .penaltyLog()
                .penaltyDeath()
                .build());
    }

    public List<LearnTypeEntity> getLearnTypeEntities() {
        return learnTypeEntities;
    }

    public void setLearnTypeEntities(List<LearnTypeEntity> learnTypeEntities) {
        LearnTypeEntity learnTypeEntity = new LearnTypeEntity("","全部题型");
        learnTypeEntities.add(0,learnTypeEntity);
        this.learnTypeEntities = learnTypeEntities;
    }
}
